package 每日一题;

import javax.lang.model.element.AnnotationMirror;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/4/28 15:03
 */
public class L1172 {

}

class DinnerPlates {
    private int capacity;
    List<Stack<Integer>> stacks;

    public DinnerPlates(int capacity) {
        this.capacity = capacity;
        stacks = new ArrayList<>();
    }

    public void push(int val) {
        int i = 0;
        for (; i < stacks.size(); i++) {
            if (stacks.get(i).size() < capacity) {
                stacks.get(i).push(val);
                break;
            }
        }
        if (i == stacks.size()) {
            Stack<Integer> stack = new Stack<>();
            stack.add(val);
            stacks.add(stack);
        }
    }

    public int pop() {
        int ans = -1;
        for (int i = stacks.size() - 1; i >= 0; i--) {
            if(!stacks.get(i).isEmpty()){
                ans = stacks.get(i).pop();
                break;
            }
        }
        return ans;
    }

    public int popAtStack(int index) {
        if(stacks.size() <= index || stacks.get(index).size() == 0)
            return -1;
        return stacks.get(index).pop();
    }
}